﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WCFMINERP.BLL.Console;
using WCFMINERP.MODEL;

namespace WCFMINERP.Console
{
    public partial class FrmConsole : Form
    {
        public FrmConsole()
        {
            InitializeComponent();
        }
        ConsoleBll _bll = new ConsoleBll();
        private void FrmConsole_Load(object sender, EventArgs e)
        {
            dateEditNormalStart.DateTime = DateTime.Now;
            dateEditNormalEnd.DateTime = DateTime.Now.AddDays(-1);
        }

        private void simpleButtonNormalOK_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            try
            {
                gridControlNormalList.DataSource = _bll.GetLoadList(dateEditNormalStart.DateTime, dateEditNormalEnd.DateTime);
                gridControlNormalList.RefreshDataSource();
            }
            catch (Exception exx)
            {
                MessageBox.Show("错误："+exx.Message);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }

        private void tabControlMain_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControlMain.SelectedIndex == 0)
            {
                dateEditNormalStart.DateTime = DateTime.Now;
                dateEditNormalEnd.DateTime = DateTime.Now.AddDays(-1);
            }
            else if (tabControlMain.SelectedIndex == 1)
            {
 
            }
        }

        private void toolStripButtonErrorRush_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;

                gridControlError.DataSource = _bll.GetErrorLoadList();
                gridControlError.RefreshDataSource();
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
            }
        }

        private void toolStripButtonRetry_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要重新解析该订单包？", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
            {
                //寻找文件先将文件从备份文件夹内拷贝回WHDL然后修改数据库状态
                UploadQueue_Info uqInfo = (UploadQueue_Info)gridViewError.GetFocusedRow();
                if (uqInfo != null)
                {
                    int rtnVal = _bll.CopyBack(uqInfo.ZipName);
                    if (rtnVal == -100)
                    {
                        MessageBox.Show("数据库连接错误，请稍候重试");
                    }
                    else if (rtnVal == -2)
                    {
                        MessageBox.Show("拷贝文件错误，请查看操作权限");
                    }
                    else if (rtnVal == -1)
                    {
                        MessageBox.Show("数据不存在");

                    }
                    else if (rtnVal == 1)
                    {
                        MessageBox.Show("操作成功，正在重试");
                    }
                    else
                    {
                        MessageBox.Show("数据不存在1");
                    }

                }
            }
        }

        private void toolStripButtonReUpload_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要重新下载该订单包？", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
            {

            }
        }

        
    }
}
